package com.okay.util;


import android.os.Build;
import android.util.Log;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class sysInfo {

    asd s;
    public void sss(){

         s =  new asd();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(1000);
                        sysInfo();

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            }
            }).start();
    }

    private void sysInfo() {
                try {
                    // 查询某一个进程的信息
                    List<String> cmds = new ArrayList<String>();
                    cmds.add("top");
                    cmds.add("-n");
                    cmds.add("1");
                    if (Build.VERSION.SDK_INT >= 26) {
                        cmds.add("-p");
                        cmds.add(android.os.Process.myPid() + "");
                    }
                    ProcessBuilder pb = new ProcessBuilder(cmds);
                    Process p = pb.start();

                    //Process p = Runtime.getRuntime().exec("top -n 1 -p " + android.os.Process.myPid());

                    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
                    StringBuilder sb = new StringBuilder();
                    String line;
                    while ((line = br.readLine()) != null) {
                        sb.append(line).append("\n");
                    }
                    Log.e("CLOUDWISE", "Sys : " + sb.toString());
                    Log.e("CLOUDWISE", "$ + :"+ Runtime.getRuntime().availableProcessors());
                } catch (Exception ex) {
                    ex.printStackTrace();
                    Log.e("CLOUDWISE", "Exception : " + ex.toString());
                }
    }

}